<template>
  <div>
    <!-- 赛事列表 -->
    <el-table v-loading="tableLoading" class="gl_mb_15 game_table_list" :data="tableData" stripe size="mini" style="width: 100%">
      <el-table-column label="分站赛logo" align="center" :width="110">
        <template slot-scope="{ row }">
          <img class="game_coverimg" :src="getStaticPhotoUrl(row.logoImage)" alt="" @error="errorPhoto">
        </template>
      </el-table-column>
      <el-table-column prop="name" label="赛事名称" :min-width="220" />
      <el-table-column label="比赛时间" align="center" :width="240">
        <template slot-scope="{ row }">
          {{ row.startDate && row.startDate.substring(0, 10) }}
        </template>
      </el-table-column>
      <el-table-column label="赛事状态" align="center" :width="140">
        <template slot-scope="{ row }">
          <span v-if="row.statusName === '报名中'" class="gl_color_success">
            <i class="el-icon-success" />
            <span class="gl_pl_5">{{ row.statusName }}</span>
          </span>
          <span v-else-if="row.statusName === '进行中'" class="gl_color_info">
            <i class="el-icon-success" />
            <span class="gl_pl_5">{{ row.statusName }}</span>
          </span>
          <span v-else class="gl_color_grey">
            <i class="el-icon-success" />
            <span class="gl_pl_5">{{ row.statusName }}</span>
          </span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" :label="$t('table.actions')" align="left" :width="250">
        <template slot-scope="{ row }">
          <el-button v-if="!row.isTop" size="mini" type="text" @click="changeJumpRoute('LeagueGameDataSubstation', row)">
            <span class="gl_color_primary">查看详情</span>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row style="text-align: center;" class="gl_pb_15">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :page-size="CompetitionRequestIdQO.MaxResultCount"
        :current-page="CompetitionRequestIdQO.Page"
        @size-change="changePageSize"
        @current-change="changePage"
      />
    </el-row>
  </div>
</template>
<script>
import defaultGameLogo from '@/assets/images/game/game_logoDefaultPhoto.png';
import { Api_GET_EventsManagementCompetitionRequestCompetitionLeagueInIsolateLeagueCompetitionIdQO } from '@/lib/form/game/swaggerForm';
import {
  api_GET_EventsManagementCompetitionRequestCompetitionLeagueInIsolateLeagueCompetitionId
} from '@/extend/api/gameswaggerApi/app.js';

export default {
  name: 'LeagueGameDataDetails',
  data() {
    return {
      defaultGameLogo: defaultGameLogo,
      CompetitionRequestIdQO: new Api_GET_EventsManagementCompetitionRequestCompetitionLeagueInIsolateLeagueCompetitionIdQO(),
      tableData: [],
      total: 0,
      tableLoading: false,
      gameId: ''
    };
  },
  created() {
    this.initForm();
  },
  methods: {
    // 初始化
    initForm() {
      this.gameId = this.$route.params.parentId;
      this.CompetitionRequestIdQO = new Api_GET_EventsManagementCompetitionRequestCompetitionLeagueInIsolateLeagueCompetitionIdQO();
      this.getPageList();
    },
    // 获取赛事列表
    getPageList(page) {
      // 默认联赛
      this.CompetitionRequestIdQO.Page = page || 1;
      this.CompetitionRequestIdQO.SkipCount = (this.CompetitionRequestIdQO.Page - 1) * this.CompetitionRequestIdQO.MaxResultCount;
      this.tableLoading = true;
      api_GET_EventsManagementCompetitionRequestCompetitionLeagueInIsolateLeagueCompetitionId(this.gameId, this.CompetitionRequestIdQO).then(res => {
        this.tableLoading = false;
        this.tableData = res.items || [];
        this.total = res.totalCount;
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 获取图片地址
    getStaticPhotoUrl(relativeUrl) {
      if (!relativeUrl) return '';
      return WEB_CONFIG.VUE_APP_STATIC_FILE_RUL + relativeUrl;
    },
    errorPhoto() {
      const img = event.srcElement;
      img.src = this.defaultGameLogo;
    },
    // 查看详情
    changeJumpRoute (code, row) {
      const { query } = this.$route;
      query.gameName = query.gameName || '';
      this.$router.push({
        name: code,
        params: { id: row.competitionId },
        query: query
      });
    },
    changePage(page) {
      this.getPageList(page);
    },
    changePageSize(pagesize) {
      this.CompetitionRequestIdQO.MaxResultCount = pagesize;
      this.getPageList();
    }
  }
};
</script>
<style lang="scss" scoped>
  .statistics_title{
    line-height: 50px;
  }
  .statistics_label{
    text-align: right;
    font-weight: bold;
  }
  .statistics_nums{
    font-size: 40px;
    color: rgb(58, 128, 236);
    margin-bottom: 10px;
  }
  .game_table_list .game_coverimg {
    max-width: 74px;
    max-height: 74px;
    border-radius: 50%;
    vertical-align: middle;
  }
</style>
